//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.farm.doc.server.impl;

import com.farm.doc.domain.FarmDocfile;
import com.farm.doc.domain.ex.DocEntire;
import com.farm.doc.server.FarmDocIndexInter;
import com.farm.doc.server.FarmDocTypeInter;
import com.farm.doc.server.FarmDocgroupManagerInter;
import com.farm.doc.server.FarmFileIndexManagerInter;
import com.farm.doc.server.FarmFileManagerInter;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Resource;
import javax.transaction.Transactional;
import org.springframework.stereotype.Service;

@Service
public class FarmFileIndexManagerImpl implements FarmFileIndexManagerInter {
	@Resource
	private FarmDocIndexInter farmDocIndexManagerImpl;
	@Resource
	private FarmFileManagerInter farmFileManagerImpl;
	@Resource
	private FarmDocTypeInter farmDocTypeManagerImpl;
	@Resource
	private FarmDocgroupManagerInter farmDocgroupManagerImpl;

	public FarmFileIndexManagerImpl() {
	}

	@Transactional
	public void addFileLuceneIndex(String fileid, DocEntire doc, String text) {
		this.farmDocIndexManagerImpl.delLuceneIndex(fileid);
		this.farmDocIndexManagerImpl.addLuceneIndex(fileid, this.farmFileManagerImpl.getFile(fileid).getName(), text,
				doc);
	}

	@Transactional
	public void delFileLucenneIndexs(List<FarmDocfile> originalfiles, List<FarmDocfile> newfiles, DocEntire doc) {
		Iterator var5 = originalfiles.iterator();

		while (var5.hasNext()) {
			FarmDocfile file = (FarmDocfile) var5.next();
			boolean isHave = false;
			Iterator var8 = newfiles.iterator();

			while (var8.hasNext()) {
				FarmDocfile filenew = (FarmDocfile) var8.next();
				if (file.getId().equals(filenew.getId())) {
					isHave = true;
				}
			}

			if (!isHave) {
				this.delFileLucenneIndex(file.getId());
			}
		}

	}

	@Transactional
	public void delFileLucenneIndex(String fileid) {
		this.farmDocIndexManagerImpl.delLuceneIndex(fileid);
	}

	public void handleFileLucenneIndexBymoveType(DocEntire oldDoce, DocEntire newdoc) {
		if (newdoc.getDoc().getDomtype().equals("5")) {
			if (!oldDoce.getType().getId().equals(newdoc.getType().getId())) {
				if (!newdoc.getType().getReadpop().equals("0")) {
					Iterator var4 = oldDoce.getFiles().iterator();

					while (var4.hasNext()) {
						FarmDocfile file = (FarmDocfile) var4.next();
						this.delFileLucenneIndex(file.getId());
					}
				}

			}
		}
	}
}
